package cn.darkhorse.mesadmin.controller.workflow;




import cn.darkhorse.common.constant.CommonConstant;
import cn.darkhorse.workflow.service.IBpmnAlreadyDealtTaskExtService;
import cn.darkhorse.workflow.vo.AlreadyDealtTaskVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户已办事项 前端控制器
 * </p>
 *
 * @author mybatis-plus-generator
 * @since 2022-08-08
 */
@RestController
@RequestMapping("/alreadydealt")
public class BpmnAlreadyDealtTaskController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;
    @Resource
    private IBpmnAlreadyDealtTaskExtService alreadyDealtTaskService;

    /**
     * 已办事项
     *
     * @param userName
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public TableDataInfo selectAlreadyDealtTask(String userName, String projectName, String formName, String formCode) {
        if (StringUtils.isBlank(userName)) {
            throw new ServiceException("缺失参数值!");
        }
        SysUser user = sysUserService.selectUserByUserName(userName);
        if (user == null || UserConstants.USER_DISABLE.equals(user.getStatus())) {
            throw new ServiceException("用户不存在！");
        }
        //startPage();
        //解决分页异常
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Page page = PageHelper.startPage(pageDomain.getPageNum(), pageDomain.getPageSize());
        List<AlreadyDealtTaskVo> alreadyDealtTaskVos = alreadyDealtTaskService.selectAlreadyDealtTask(userName, projectName, formName, formCode);
        TableDataInfo dataTable = getDataTable(alreadyDealtTaskVos);
        dataTable.setTotal(page.getTotal());
        return dataTable;
    }
}
